package com.org.any.autocar;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import com.autocar.reader.R;
import com.autocar.reader.adapter.ProductDemandAdapter;
import com.autocar.reader.bean.SupplyListBean;
import com.autocar.reader.bean.SupplySubBean;
import com.autocar.reader.util.NewDataToast;
import com.autocar.reader.view.XListView;
import com.org.any.autocar.fragment.IopenSupply;

public class SearchResultSupplyActivity extends BaseActivity implements
		IopenSupply {

	private ImageView backIv;
	private XListView moodsXl;
	private ProductDemandAdapter demandAdapter;
	private SupplyListBean slbeans;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.search_product_sub_layout);
		initIntent();
		initview();
		initproperty();
	}

	private void initIntent() {
		Intent intent = getIntent();
		slbeans = (SupplyListBean) intent.getSerializableExtra("bean");
		if (slbeans == null) {
			NewDataToast.makeText(getApplicationContext(),
					"get ProductDetailBean is null", false).show();
			finish();
		}
		Log.e("mg", "bean: " + slbeans.getNext_url());
	}

	private void initproperty() {
		demandAdapter.setListSupplySubBean(slbeans.getListBeans());
	}

	private void initview() {
		backIv = (ImageView) findViewById(R.id.search_product_sub_top_iv_back);

		backIv.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				gotoMain();
			}
		});

		moodsXl = (XListView) findViewById(R.id.search_product_sub_xlv_moods);

		demandAdapter = new ProductDemandAdapter(this, this);
		moodsXl.setAdapter(demandAdapter);
		moodsXl.removeHeader();
		moodsXl.removeFooter();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			gotoMain();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	private void gotoMain() {
		hideLoadPb();
		finish();
	}

	@Override
	public void finish() {
		super.finish();
		overridePendingTransition(R.anim.fade_in, R.anim.right_out_anim);
	}

	@Override
	public void opentSupply(SupplySubBean bean) {
		Intent intent = new Intent(this, ProductSupplyActivity.class);
		intent.putExtra("bean", bean);
		startActivity(intent);
		overridePendingTransition(R.anim.right_in_anim, R.anim.fade_out);
	}

}
